from selenium.webdriver.common.by import By

from pages.bases.bases import BasesPage


class ServerCoPage(BasesPage):
    def __init__(self):
        super().__init__("web")
        # 标题
        self.lable = (By.XPATH, '//*[@placeholder="请输入，30个字以内"]')
        # 协同工作描述
        self.xtwork = (By.XPATH, '//*[@placeholder="请输入，500个字以内"]')
        # 协同工作类型
        self.xttype = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[2]/div[2]/div/div/div/'
                                 'div[1]/span[1]')
        # 选择协同工作
        self.xttypetext = (By.XPATH, '//li[@data-v-6a6f1dab][contains(text(), "测试")]')
        # 项目属地
        self.possession = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[2]/div[3]/div/div/'
                                     'div/div/div[1]/div[1]/input')
        # 选择省份
        self.province = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[2]/div[3]/div/div/div/'
                                   'div/''div[2]/div/span/ul/li[1]')
        # 选择城市
        self.city = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[2]/div[3]/div/div/div/div/'
                               'div[2]/div/span/span/ul/li[1]')
        # 对象部门处理人
        self.departmentpeo = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[3]/div[1]/div/'
                                        'div/div/div/div[1]/input[2]')
        # 选择部门
        self.department = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[3]/div[1]/div/'
                                     'div/div/div/div[2]/ul[2]/div/div[1]/ul/li')
        # 选项执行人
        self.executor = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[3]/div[1]/div/div/div/'
                                   'div/div[2]/ul[2]/div/div[2]/li')

        # 选择抄送
        self.copysend = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[3]/div[2]/div/div/div/'
                                   'div/div[1]/input[2]')
        # 选择抄送人部门
        self.senddepart = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[3]/div[2]/div/div/'
                                     'div/div/div[2]/ul[2]/div/div[1]/ul/li')
        # 选择抄送人
        self.sendpeo = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[1]/div/form/div[3]/div[2]/div/div/div/'
                                  'div/div[2]/ul[2]/div/div[2]/li')
        # 提交按钮
        self.button = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[4]/div/div[2]/div[1]/button[1]')

    def input_data(self, lable, xtwork, department, executor, senddepart=None, sendpeo=None):
        '''
        :param lable: 标题
        :param xtwork: 协同工作输入文本
        :param department: 部门
        :param executor: 部门执行人
        :param senddepart: 抄送部门
        :param sendpeo: 抄送人
        '''
        self.input_text(self.lable, lable)
        # self.driver.execute_script(self.JS)
        # self.clear(self.completiontime)
        # sleep(1)
        # self.input_text(self.completiontime, '2023-09-21 14:01')
        self.input_text(self.xtwork, xtwork)
        self.click(self.xttype)
        self.click(self.xttypetext)
        self.click(self.possession)
        self.click(self.province)
        self.click(self.city)
        self.click(self.departmentpeo)
        self.select_type(self.department, department)
        self.select_type(self.executor, executor)
        try:
            self.click(self.copysend)
            self.select_type(self.senddepart, senddepart)
            self.select_type(self.sendpeo, sendpeo)
        finally:
            self.click(self.button)
